<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<script>
  console.log('123');
  const foo = 'bar';
  console.group(foo);
  //属性名=foo 值=bar
  const baz = {foo};
  console.log(baz);
  //对象初始化
  const object = {hah: 'haha'}
  console.log(object);
  console.groupEnd('end')

  const x = 'xxxx'
  const y = 'yyyy'
  const object1 = {
    x, y,
    put() {
      console.log('in put')//简写
    },
    f: function () {//常规写法 一样的
      console.log('in f')
    }
  }
  object1.put()
  object1.f()
  const propKey = 'test'
  //第一个x是对象的属性名，不用加括号，第二个属性的值，与属性名相同可以省略
  //引号是省略的结果
  const object2 = {
    'x': x,
    y,
    [propKey]: true,
    ['a' + 'bc']: 123,
    'put': function () {
      console.log('in put')
    }
  }
  console.log(object1)
  console.log(object2)
  console.log(object1.put.name)

  function getPoint() {
    const x = 1;
    const y = 10;
    return {x, y};
  }

  console.log(getPoint())
  console.log('属性名表达式')
  console.log(object1.x)
  console.log(object1['y'])

  let lastWord = 'last word';

  const a = {
    'first word': 'hello',
    [lastWord]: 'world'
  };

  console.log(a['first word']) // "hello"
  console.log(a[lastWord]) // "hello"
  console.log(a['last word']) // "hello"
  // "world"
  // "world"
</script>
</body>
</html>
